﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace XNAControls
{
    public class TextBox : XNAControl
    {
        public string Text { get; set; }
        public Color ForeColor { get; set; }
        public SpriteFont Font { get; set; }

        public TextBox()
            : base()
        {
            Text = "";
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);
            if (Visible)
            {
                if (Font == null)
                {
                    throw new ArgumentNullException("Font not set");
                }

                string textToDraw = Text;

                while (Font.MeasureString(textToDraw).Y > Size.Y)
                {
                    textToDraw = textToDraw.Substring(1);
                }

                spriteBatch.DrawString(Font, textToDraw, new Vector2(AbsolutePosition.X, AbsolutePosition.Y), ForeColor);

            }
        }
    }
}
